package com.shenmazong.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 阿瑞
 * @version 1.0
 * @description TODO
 * @class MqCOnfig ???
 * @date 2021/9/25 13:47
 */
@Configuration
public class MqConfig {

    public static final String COMPANY_QUEUE="company_queue";
    public static final String COMPANY_KEY="company_queue";

    public static final String JOB_QUEUE="job_queue";
    public static final String JOB_KEY="job_queue";

    public static final String SOFTWARE_QUEUE="software_queue";
    public static final String SOFTWARE_KEY="software_queue";

    public static final String BOTIAN_EXCHANGE="botian_exchange";
    /**
     *实现增量添加
     */
    //创建公司队列
    @Bean("company")
    public Queue getCompanyQueue(){
        return new Queue(COMPANY_QUEUE);
    }
    //创建岗位队列
    @Bean("job")
    public Queue getJobQueue(){
        return new Queue(JOB_QUEUE);
    }
    //创建软件队列
    @Bean("software")
    public Queue getSoftwareQueue(){
        return new Queue(SOFTWARE_QUEUE);
    }
    //创建Exchange
    @Bean("botian")
    public DirectExchange botianExchange(){
        return new DirectExchange(BOTIAN_EXCHANGE);
    }
    //绑定Exchange与公司队列
    @Bean
    public Binding companyToBotian(@Qualifier("company")Queue queue,@Qualifier("botian")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with(COMPANY_KEY);
    }
    //绑定Exchange与岗位队列
    @Bean
    public Binding jobToBotian(@Qualifier("job")Queue queue,@Qualifier("botian")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with(JOB_KEY);
    }
    //绑定Exchange与软件队列
    @Bean
    public Binding softwareToBotian(@Qualifier("software")Queue queue,@Qualifier("botian")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with(SOFTWARE_KEY);
    }
    


}
